{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-03-09T02:13:55.579978Z",
     "start_time": "2024-03-09T02:13:55.573145Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bad Request\n"
     ]
    }
   ],
   "source": [
    "# python3.9以上的版本才能用match\n",
    "http_response_status = 400\n",
    "\n",
    "match http_response_status:\n",
    "    case 400:\n",
    "        print(\"Bad Request\")\n",
    "    case 404:\n",
    "        print(\"Not Found\")\n",
    "    case 418:\n",
    "        print(\"I'm a teapot\")\n",
    "    case _:\n",
    "        print(\"Something went wrong\")"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4xxx error\n"
     ]
    }
   ],
   "source": [
    "http_response_status = 400\n",
    "\n",
    "match http_response_status:\n",
    "    case 400 | 404 | 418:\n",
    "        print(\"4xxx error\")\n",
    "    case 500 | 501 | 503:\n",
    "        print(\"5xxx error\")\n",
    "    case _:\n",
    "        print(\"Something went wrong\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-09T02:15:09.453247Z",
     "start_time": "2024-03-09T02:15:09.448175Z"
    }
   },
   "id": "5a1a9bad6dc20e5a",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "1004f3e8ead465c2"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
